<template>
	<view class="userBusinessCard">
		<view class="" @click="dsadwq">
			提交
		</view>
		<template v-if="userBusinessCard">
			<view class="_for" v-for="item in newUserBusinessCard">
				<view class="name">{{item.name}}</view>
				<textarea v-model="item.value"></textarea>
			</view>
			
		</template>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userBusinessCard:null,
				userUid:"",
				newUserBusinessCard:[],
				bio:""
			}
		},
		onLoad() {
			uni.request({
				url:this.$_configFile() + "global.json",
				success: (res) => {
					this.userBusinessCard = res.data.userBusinessCard;
					this.getUserDetail();
				}
			})
		},
		methods: {
			dsadwq(){
				console.log(this.bio)
				console.log(this.newUserBusinessCard)
			},
			getUserDetail(){
				this.userUid = JSON.parse(uni.getStorageSync('accountAuthToken')).uid;
				this.$_request(
					"GET",`/api/fresns/v1/user/${this.userUid}/detail`,
					{},
					(res) => {
					// if(res.data.data.detail.bio){
					// 	let a = `根节点开始了估计看就看放到数[youranbio-gongsi]公司公司[/youranbio-gongsi][youranbio-zhiwei]职位职位哈哈哈[/youranbio-zhiwei][youranbio-key]名字哈哈哈[/youranbio-key]`;
						  
					// 	this.newUserBusinessCard = matchAndReplace(a, this.userBusinessCard);  
					// 	console.log(this.newUserBusinessCard);
					// }


						this.bio = `根节点开始了估计看就看放到数[youranbio-gongsi]公司公司[/youranbio-gongsi][youranbio-zhiwei]职位职位哈哈哈[/youranbio-zhiwei][youranbio-key]名字哈哈哈[/youranbio-key]`;

						this.newUserBusinessCard = this.matchAndReplace(this.bio, this.userBusinessCard);



						//console.log(this.userDetailBio)
					}
				)
			},
			matchAndReplace(bio, data) {
				data.forEach(obj => {
					const key = obj.key;
					const regex = new RegExp(`\\[youranbio-${key}\\](.*?)\\[\\/youranbio-${key}\\]`, 'g');
					const match = bio.match(regex);
			
					if (match) {
						// 如果有匹配项，则取第一个匹配项（假设每个key只出现一次）  
						const value = match[0].slice(`[youranbio-${key}]`.length, -`[/youranbio-${key}]`.length).trim();
						obj.value = value;
					}
				});
				return data.map(obj => ({ ...obj }));
			},
		}
	}
</script>

<style lang="scss">
.userBusinessCard{
	._for{
		padding: 25rpx;
		.name{
			font-size: 32rpx;
			line-height: 32rpx;
		}
		textarea{
			background: #FFF;
			
		}
		.button{
			
		}
	}
}
</style>
